-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(engine): Populating process instance id in jobs #4334
base: master
Are you sure you want to change the base?
Conversation
@yanavasileva, |
Hi @punitdarira, Thank you for raising this pull request and showing interest in our product.
Why you need the field there? The
In Cockpit, we display all job logs with the specific Lastly, don't forget to cover the made changes with test cases. Hope that helps you to continue with the contribution. Best, |
Hi Yana, Line 93 in 3f6cb30
The above line gets invoked from Regarding tests, can you please guide whether we should go for new test file for AbstractBatchJobHandler where we simply mock or do we deploy a bpmn file in a test case and check whether instance and definition ids are set? |
I missed that, however, in debug mode and in general the historic job logs doesn't inherit the process definition id from the batch job entity. At the moment, I can't say why is that. So we need to understand why and fix it eventually.
I think we can add a test case(s) to existing classes that test batch execution. Here's an example of single invocation test for set variables we have at the moment: https://github.com/camunda/camunda-bpm-platform/blob/master/engine/src/test/java/org/camunda/bpm/engine/test/api/runtime/SetVariablesBatchTest.java#L673-L695. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed above, the pull request needs more work.
Hi Yana, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposed changes cause failures in other batch tests. Also, I would expect the have tests for all batches for which this change make sense.
we can maybe just add a new assert statement to the above mentioned method with a comment
Yes, you can consider doing that where it make sense add comments (and/or adjust test name) so people are not lost what is tested.
engine/src/main/java/org/camunda/bpm/engine/impl/batch/AbstractBatchJobHandler.java
Outdated
Show resolved
Hide resolved
assertEquals(processInstance.getProcessDefinitionId(), jobLog.getProcessDefinitionId()); | ||
assertEquals(processInstance.getRootProcessInstanceId(), jobLog.getProcessInstanceId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ The checks are performed for the historic job log, I would expect to check the jobs as well.
Hi @yanavasileva,
3rd solution would be the least invasive and clearer. Can you please advice? |
@punitdarira, I am not sure either of the options is great when we think about performance. |
sounds good |
@punitdarira, I checked with the team, we want to keep it simple for now and only populate the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added adjustment for the processDefinitionId
field.
engine/src/main/java/org/camunda/bpm/engine/impl/batch/AbstractBatchJobHandler.java
Outdated
Show resolved
Hide resolved
engine/src/main/java/org/camunda/bpm/engine/impl/batch/AbstractBatchJobHandler.java
Outdated
Show resolved
Hide resolved
related to camunda#4205
...e/src/test/java/org/camunda/bpm/engine/test/api/runtime/RestartProcessInstanceAsyncTest.java
Show resolved
Hide resolved
@punitdarira, are you willing to add further test coverage that the process instance id is populated for other/all type of batch operations? |
import org.camunda.bpm.engine.impl.util.JsonUtil; | ||
|
||
import static org.camunda.bpm.engine.impl.RestartProcessInstancesBatchConfigurationJsonConverter.PROCESS_DEFINITION_ID; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Not needed anymore:
import org.camunda.bpm.engine.impl.util.JsonUtil; | |
import static org.camunda.bpm.engine.impl.RestartProcessInstancesBatchConfigurationJsonConverter.PROCESS_DEFINITION_ID; |
@yanavasileva |
@yanavasileva , However, there were 3 batch types which were operating on batches directly like- For these jobs, the processInstanceId is not being set as expected. I can see the job's id being set instead of the processInstaceId. Just to confirm, the execution jobs for these 3 batches should have the process instacancesId of the transitive instance right? |
Thanks for adding the tests. 💯
I will check and get back to you. The first one, we won't need a process instance id but I am not sure for the others. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not ready with the review. However, I am sharing my comments to prevent losing them.
Some adjustments needs to be done for suspend and migration batches, I will look at that.
@Test | ||
public void shouldCreateProcessInstanceRelatedBatchJobsForSingleInvocations(){ | ||
// when | ||
Batch batch = historyService.deleteHistoricDecisionInstancesAsync(decisionInstanceIds, null); | ||
helper.executeSeedJob(batch); | ||
|
||
//then | ||
//Making sure that processInstanceId is set in execution jobs #4205 | ||
assertThat(helper.getExecutionJobs(batch)) | ||
.extracting("processInstanceId") | ||
.containsExactlyInAnyOrder(decisionInstanceIds.toArray()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ The processInstanceId should not be populated for this type of a batch. It is incorrect to store the decision ids as process instance ids.
@Test | |
public void shouldCreateProcessInstanceRelatedBatchJobsForSingleInvocations(){ | |
// when | |
Batch batch = historyService.deleteHistoricDecisionInstancesAsync(decisionInstanceIds, null); | |
helper.executeSeedJob(batch); | |
//then | |
//Making sure that processInstanceId is set in execution jobs #4205 | |
assertThat(helper.getExecutionJobs(batch)) | |
.extracting("processInstanceId") | |
.containsExactlyInAnyOrder(decisionInstanceIds.toArray()); | |
} |
@@ -109,6 +111,21 @@ public void testDeleteHistoryProcessInstancesAsyncWithList() throws Exception { | |||
assertAllHistoricProcessInstancesAreDeleted(); | |||
} | |||
|
|||
@Test | |||
public void testDeleteHistoryProcessInstances_shouldCreateProcessInstanceRelatedBatchJobsForSingleInvocations() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 Better
public void testDeleteHistoryProcessInstances_shouldCreateProcessInstanceRelatedBatchJobsForSingleInvocations() { | |
public void shouldPopulateProcessInstanceIdToBatchJobsForSingleInvocations() { |
|
||
//Making sure that processInstanceId is set in execution jobs #4205 | ||
assertThat(executionJobs) | ||
.extracting("processInstanceId") | ||
.containsExactlyInAnyOrder(query.list().stream().map(HistoricDecisionInstance::getId).toArray()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Process instance id should not be populated for decision related batches:
//Making sure that processInstanceId is set in execution jobs #4205 | |
assertThat(executionJobs) | |
.extracting("processInstanceId") | |
.containsExactlyInAnyOrder(query.list().stream().map(HistoricDecisionInstance::getId).toArray()); |
|
||
HistoricDecisionInstanceQuery query = historyService.createHistoricDecisionInstanceQuery(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Not needed:
HistoricDecisionInstanceQuery query = historyService.createHistoricDecisionInstanceQuery(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ ✍️ Please check test #createModificationJobs()
is failing. processInstanceId assertions must be adjusted.
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to myself:
❓ Tests failures due to Entity was updated by another transaction concurrently
. What's wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See: org.camunda.bpm.engine.impl.persistence.entity.JobManager.updateJobSuspensionStateByProcessInstanceId(String, SuspensionState)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to myself:
Tests failures due to
java.lang.NullPointerException: null
at org.camunda.bpm.engine.impl.persistence.entity.JobEntity.setExecution(JobEntity.java:259)
at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.restoreProcessInstance(ExecutionEntity.java:1384)
See org.camunda.bpm.engine.impl.migration.instance.parser.MigratingInstanceParser.fetchJobs(CommandContext, String)
@@ -169,6 +169,11 @@ protected void createJobEntities(BatchEntity batch, T configuration, String depl | |||
ByteArrayEntity configurationEntity = saveConfiguration(byteArrayManager, jobConfiguration); | |||
|
|||
JobEntity job = createBatchJob(batch, configurationEntity); | |||
|
|||
if (jobConfiguration.getIds() != null && jobConfiguration.getIds().size() == 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this will be required to avoid populating the ids for entities that are not process instance:
if (jobConfiguration.getIds() != null && jobConfiguration.getIds().size() == 1) { | |
if (jobConfiguration.getIds() != null && jobConfiguration.getIds().size() == 1 | |
&& !(this instanceof DecisionSetRemovalTimeJobHandler) | |
&& !(this instanceof DeleteHistoricDecisionInstancesJobHandler) | |
&& !(this instanceof SetJobRetriesJobHandler) | |
&& !(this instanceof SetExternalTaskRetriesJobHandler) | |
// && !(this instanceof BatchSetRemovalTimeJobHandler) | |
) { |
Just dropping by to say that I didn't have the chance to work on this. |
related to #4205